<template>
  <div class="box">
    <h1>确认挂号信息</h1>
    <el-card>
      <template #header>
        <div class="header">
          <span> 请选择就诊人</span>
          <el-button type="primary" :icon="Plus" @click="goAddPatient"
            >添加就诊人</el-button
          >
        </div>
      </template>
      <div class="content">
        <div class="item" v-for="item in patientList" :key="item._id" @click="selectPatient(item._id)" >
          <PatientCard :patient="item"></PatientCard>
          <Transition name="cur" >
            <div class="cur" v-show="currentId==item._id" >
            已选择
          </div>
          </Transition>
        </div>
      </div>
    </el-card>
    <el-card class="card1">
      <el-descriptions class="margin-top" :column="2" border>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon><Tickets /></el-icon>
              <span>就诊日期</span>
            </div>
          </template>
          <span>{{ DchInfo.date }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon>
                <School />
              </el-icon>
              <span>就诊医院</span>
            </div>
          </template>
          武汉第一人民医院
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon>
                <Discount />
              </el-icon>
              <span>就诊科室</span>
            </div>
          </template>
          {{ DchInfo.doctorId?.TweDepart }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon>
                <User />
              </el-icon>
              <span>医生姓名</span>
            </div>
          </template>
          <span>{{ DchInfo.doctorId?.name }}</span>
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon>
                <Avatar />
              </el-icon>
              <span>医生职称</span>
            </div>
          </template>
          {{ DchInfo.doctorId?.job?.jName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template #label>
            <div class="cell-item">
              <el-icon>
                <Money />
              </el-icon>
              <span>医院服务费</span>
            </div>
          </template>
          {{ DchInfo.price }}元
        </el-descriptions-item>
      </el-descriptions>
    </el-card>
    <div class="fullter">
      <el-button
        type="primary"
        @click="confirmRegistration"
        size="large"
        :disabled="!currentId"
        >确认挂号</el-button
      >
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { getPatientListAPI } from "@/api/patient";
import { getDocSchDetailAPI } from "@/api/DocSch";
import { createOrderAPI } from '@/api/order'
import {
  Plus,
  Tickets,
  School,
  Discount,
  User,
  Avatar,
  Money,
} from "@element-plus/icons-vue";
import useConfigStore from "@/stores/moudels/configStore";
import { useRoute, useRouter } from "vue-router";
import PatientCard from "@/views/user/manage/PatientCard/index.vue";
let route = useRoute();
let router = useRouter();
let configStore = useConfigStore();
let patientList = ref([]);
let DchInfo = ref({});
let currentId = ref('')
onMounted(() => {
  getPatientList();
  getDocSchDetail();
});
const getPatientList = async () => {
  let result = await getPatientListAPI();
  patientList.value = result.data;
};
const goAddPatient = () => {
  setTimeout(() => {
    configStore.changePatientShow(2);
  }, 100);
  router.push({
    path: "/user/manage",
    query: {
      isBack: route.fullPath,
      pId: route.query?.id
    },
  });
};
const selectPatient = (id)=>{
  currentId.value = id
}
//获取排班详情
const getDocSchDetail = async () => {
  let result = await getDocSchDetailAPI(route.query?.id);
  DchInfo.value = result.data;
};
//确认挂号的回调
const confirmRegistration = async () => {
  let result = await createOrderAPI({
    patientId:currentId.value,
    doctorId:DchInfo.value.doctorId?._id,
    scheduleId:route.query?.id
  })
  console.log(result);
  router.push({
    path:'/user/detail',
    query:{
      id:result.data._id
    }
  })
};
</script>

<style lang="scss" scoped>
.box {
  h1 {
    font-size: 20px;
    color: #656565;
    margin-bottom: 20px;
    font-weight: 900;
  }
  .header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    span {
      font-size: 16px;
      color: #656565;
    }
  }
  .content {
    display: flex;
    flex-wrap: wrap;
    .item {
      position: relative;
      .cur {
      position: absolute;
      left: 20%;
      top: 20%;
      width: 200px;
      height: 200px;
      text-align: center;
      line-height: 200px;
      border-radius: 50%;
      border: 2px dashed red;
      color: red;
      opacity: 0.6;
      font-weight: 900;
      transform: rotate(35deg);
    }
    .cur-enter-from {
      transform: scale(1);
    }
    .cur-enter-active {
      transition: all 0.3s;
    }
    .cur-enter-to {
      transform: scale(1.2);
    }
    }
  }
  .card1 {
    margin-top: 10px;
    .cell-item {
      display: flex;
      align-items: center;
      span {
        margin-left: 6px;
      }
    }
  }
  .fullter {
    display: flex;
    justify-content: center;
    margin-top: 20px;
  }
}
</style>
